package com.qf.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionUtil {

    public static Connection getConnection() throws IOException, TimeoutException {
        //1. 创建ConnectionFactory
        ConnectionFactory factory = new ConnectionFactory();

        //2. 给ConnectionFactory设置连接RabbitMQ的信息
        factory.setHost("192.168.41.41");
        factory.setPort(5672);
        factory.setUsername("gp07");
        factory.setPassword("gp07");
        factory.setVirtualHost("gp07");

        //3. 通过工厂获取Connection
        Connection connection = factory.newConnection();

        //4. 返回
        return connection;
    }
}
